const { defineConfig } = require('@vue/cli-service');
const path = require("path")
const { LOGO_TYPE, SYS_NAME } = require("./src/config/common_config")
const icon = path.join('public', LOGO_TYPE === 'zhy' ? "favicon.png" : "xnLogo.png")
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    host: '127.0.0.1',
    port: 9001,
    hot: true,
    proxy: {
      // 远程文件
      '/FSOP': {
        target: 'http://192.168.100.104',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        },
      },
      // 后端接口
      '/api': {
        target: 'http://127.0.0.1:9999',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/api'
        }
      },
    },
    client: {
      overlay: false, // 禁止Error错误覆盖客户端
    },
  },
  pluginOptions: {
    electronBuilder: {
      outputDir: 'webroot_electron',
      preload: 'src/preload/index.js',
      builderOptions: {
        productName: SYS_NAME,
        compression: "maximum", // 打包压缩
        // afterPack: 'script/afterPack.js', // 构建完成后运行的钩子
        extraResources: [
          { "from": "config.json", "to": "." }, // 打包后暴露配置文件
          { "from": "grpc_server", "to": "./grpc_server" } // 打包后暴露服务端程序
        ],
        win: {
          icon,
          target: [{
            target: 'nsis',
          }],
          protocols: [{
            name: "downloader-app",
            schemes: ["downloader-app"]
          }],
          // 以管理员权限运行
          requestedExecutionLevel: 'requireAdministrator'
        },
        nsis: {
          oneClick: false,
          perMachine: true,
          allowToChangeInstallationDirectory: true, // 允许用户更改安装目录
          include: "script/installer.nsh",
        },
        linux: {
          icon,
          target: 'AppImage',
          maintainer: "zj",
        },
        mac: {
          icon
        },
      }
    }
  },
});
